package br.com.carser.business.infra;

import java.io.Serializable;
import java.util.List;

import br.com.carser.dao.infra.BaseEntity;
import br.com.carser.exception.DuplicateEntityException;
import br.com.carser.exception.ParentEntityException;

/**
 * <B>Project: carser-web</B><BR>
 * 
 * Used for Basic CRUD operations.
 * 
 * <DL>
 * <DT><B>Created:</B>
 * <DD>Sep 20, 2011</DD></DT>
 * </DL>
 * <DL>
 * <DT><B>Last Modification:</B>
 * <DD>Sep 20, 2011</DD></DT>
 * </DL>
 * 
 * @author Caio Carleto - CarSer - Sep 20, 2011
 * @version 1.0
 */
public interface BaseBusiness<T extends BaseEntity> extends Serializable {
	
	/**
	 * Get entity by id.
	 * @param id Entity id.
	 * @return entity.
	 */
	T getById(Long id);
	
	/**
	 * Save or update a entity.
	 * 
	 * @param entity entity to save.
	 * @return entity syncronized with database.
	 * @throws DuplicateEntityException 
	 */
	T saveOrUpdate(T entity) throws DuplicateEntityException;
	
	/**
	 * Delete a entity.
	 * @param entity Entity to delete.
	 * @throws ParentEntityException 
	 */
	void delete(T entity) throws ParentEntityException;
	
	/**
	 * Refresh a entity.
	 * @param entity Entity to refresh.
	 */
	void refresh(T entity);
	
	/**
	 * Get entity with LOCKMODE of type READ (Optmistic lock).
	 * 
	 * @param id Entity id.
	 * @return entity.
	 */
	T getByIdForUpdate(Long id);
	
	/**
	 * Get all.
	 * 
	 * @return list.
	 */
	List<T> getAll();
}
